import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/order/order-invoice';


export interface OrderInvoiceParam {
    orderId?: string;
    invoiceType?: number;
    invoiceReceiverPhone?: string;
    companyName?: string;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface OrderInvoiceResponse {
    id?: number;
    orderId: string;
    invoiceType?: number;
    invoiceTitle?: string;
    invoiceContent?: string;
    invoiceTaxNo?: string;
    invoiceReceiverPhone?: string;
    invoiceReceiverEmail?: string;
    invoiceReceiverAddress?: string;
    companyName?: string;
    companyAddress?: string;
    telphone?: string;
    bankName?: string;
    bankAccount?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface OrderInvoiceSaveCommand {
    id?: number;
    orderId: string;
    invoiceType: number;
    invoiceTitle?: string;
    invoiceContent?: string;
    invoiceTaxNo?: string;
    invoiceReceiverPhone?: string;
    invoiceReceiverEmail?: string;
    invoiceReceiverAddress?: string;
    companyName?: string;
    companyAddress?: string;
    telphone?: string;
    bankName?: string;
    bankAccount?: string;
}

export interface OrderInvoiceResponseList {
    list: OrderInvoiceResponse[];
    total: number;
}


// 通过OrderInvoiceParam参数获取分页列表
export function pageOrderInvoice(params: OrderInvoiceParam) {
    return axios.get<OrderInvoiceResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取订单发票信息
export function getOrderInvoice(id: number) {
    return axios.get<OrderInvoiceResponse>(`${BASE_URL}/${id}`);
    
}

export function listOrderInvoice(params: OrderInvoiceParam) {
    return axios.get<OrderInvoiceResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加订单发票
export function addOrderInvoice(params: OrderInvoiceSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新订单发票
export function updateOrderInvoice(params: OrderInvoiceSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除订单发票
export function deleteOrderInvoice(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}